package cn.wolfcode.p2p.methodInterceptor;

import cn.wolfcode.p2p.anno.CheckDataSource;
import cn.wolfcode.p2p.util.Constant;
import cn.wolfcode.p2p.util.DataSourceUtil;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class MyMethodInvokeInterceptor implements MethodInterceptor {

    @Override  
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        CheckDataSource annotation = methodInvocation.getMethod().getAnnotation(CheckDataSource.class);
        if(annotation != null && annotation.value().equals(Constant.SLAVE)){
                DataSourceUtil.setDatasourceKey(Constant.SLAVE);

        }
        Object object = methodInvocation.proceed();
        return object;  
    }  
}  